#ifndef KORLAPADMIN_H
#define KORLAPADMIN_H

#ifdef __QT5_TARGET

#include <QtCore/QHash>
#include <QtCore/QModelIndex>
#include <QtWidgets/QHeaderView>
#include <QtWidgets/QListWidget>
#include <QtWidgets/QMainWindow>
#include <QtWidgets/QMessageBox>
#include <QtWidgets/QTableWidgetItem>

#else

#include <QtGui/QMainWindow>
#include <QMessageBox>
#include <QHash>
#include <QListWidget>
#include <QTableWidgetItem>
#include <QModelIndex>
#include <QHeaderView>

#endif

#include "ui_korlapadmin.h"
#include "korlapadmin_model.h"
#include "Exception.h"
#include "NameValidator.h"
#include "NumberValidator.h"
#include "UniqueFileNumberValidator.h"
#include "UniquePhoneNumberValidator.h"
#include "Patient.h"
#include "Filter.h"
#include "Schedule.h"
#include "ScheduleTableModel.h"
#include "ScheduleTableView.h"
#include "CalendarModel.h"
#include "PatientNameListModel.h"
#include "FileNoListModel.h"
#include "CurrentDayDelegate.h"
#include "SeparatorDelegate.h"

class korlapAdmin_model;
class KorlapAdmin : public QMainWindow
{
	Q_OBJECT
		public slots:
			void on_addPatientPushButton_clicked();
			void on_addPatientButton_clicked();
			void on_comboBox_currentIndexChanged(int index);
			void on_phonePrefixLineEdit_textChanged(const QString& text);
			void on_addPatientNameTextBox_textChanged(const QString& text);
			void on_addFileNumberLineEdit_textChanged(const QString& text);
			void on_phoneSuffixLineEdit_textChanged(const QString& text);
			void on_phoneComboBox_currentIndexChanged(int index);
			void on_fileNrcomboBox_currentIndexChanged(int index);
			void on_filterComboBox_currentIndexChanged(int index);
			void on_patientNameCombo_currentIndexChanged(int index);
			void on_FileCombo_currentIndexChanged(int index);
			void on_phoneCombo_currentIndexChanged(int index);
			void on_resetDefaultButton_clicked();
			void on_resetButton_clicked();
			void pushButtonOnEnter();
			void popupTimeSelector(const QDate& date);
			void on_columnWidthSpinBox_valueChanged(int i);
			void on_rowHeightSpinBox_valueChanged(int i);
public:
	KorlapAdmin(QWidget *parent = 0, Qt::WindowFlags flags = 0);
	~KorlapAdmin();
	void setupCalendarView();

private:
	Ui::KorlapAdminClass ui;
	QList<int> calculateDaysOfWeek();
	int initDataBase();
	bool isValid(int index);
	bool patientsAllright();
	void setEventFilters();
	void setValidators();
	void fillInfoTable(const Patient* p);
	void fillPatientBox();
	void fillPhoneBox();
	void fillFilenrBox();
	void fillFilterBox();
	void loadDefaultFilter();
	void loadBackInfoTable(const Patient* p);
	void clearInfoTable();
	void hidePatientForm();
	void hideInfoTable();
	void refreshPatientCombo();
	void showInfoTable();
	void colourLabels();
	void colourLabel(QLabel * label,QString col);
	bool validatePatientName(bool verbose);
	bool validateFileNr(bool verbose);
	bool validatePhoneNr(bool verbose);
	void loadFilter(const QString& name);
	void loadTimeSelector();
	void setFilter();
	int errors[3];
	bool lastState;
	bool justInserted;
	void connectSignalSlots();
	const Patient* currentPatient;
	const Filter* filter;
	int currentIndeces[3];
	bool comboboxSelected;
	bool hadError;
	bool initialized;
	bool rowInsertionFinished;
	QStringListModel *phoneListModel;
	PatientNameListModel* nameListModel;
	FileNoListModel* fileListModel;
	QLocale* locale;
	ScheduleTableView* calendarView;
	CalendarModel* calendarModel;

	UniqueFileNumberValidator* uniqueValidator;
	NameValidator* nameValidator;
	UniquePhoneNumberValidator* phoneNumberValidator;
	korlapAdmin_model * model;
	QMessageBox messageBox;
	//NotEmptyValidator NEvalidator;
	//NumberAndNotEmptyValidator NNvalidator;
};

#endif // KORLAPADMIN_H
